<?php
/**
 *
 *
 * @author Zeon <scplay@gmail.com>
 * @date 2018/11/13 16:52
 * @copyright PanxSoft Inc.
 */

namespace App\Exceptions\Concerns;

use App\Exceptions\ApiAbstractException;
use App\Services\Utils\FormatLog;
use Exception;

trait HandleUncaughtException
{
    /**
     * @param Exception $e
     *
     * @throws Exception
     */
    protected function logUncaughtRequest(Exception $e): void
    {
        if ($this->shouldntReport($e) ||
            $e instanceof ApiAbstractException) {
            return;
        }

        $method_path = FormatLog::request();
        logger()->error($method_path);

        /** @var array|string $req - hack for log error type hint need string */
        $req = request()->all();
        if ($req) {
            logger()->error(PHP_EOL. request());
            logger()->error($req);
        }
    }
}